// pages/index/shopInformation/shopInformation.js
import util from '../../../utils/util.js';
import $ from '../../../utils/ajax.js';
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        storeId:"",
        topContent:{},
        centreContent:{},
        shopList:{
            timeType:1,
            page:1,
            size:10
        },
        content:[],
        loginNav: 1,
        arrList: ['', '服务费', '代理费', '租金', '会员充值', '提现', '订单逾期', '', '', '', '订单补贴']
    },
  

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (load) {
        this.setData({
            storeId: load.storeId
        })
        
    },
    onShow() {
        this.storeDetail()
        this.storeMoney()
        this.storeIncomeList()
    },
    //拨打电话
    goPhone(e) {
        const phone = e.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: phone
        })
    },
    //切换日期
    navStep(e) {
        const num = Number(e.target.dataset.num)
        switch(num)
        {   
            case 0:
            this.setData({
                ['shopList.timeType']: 0,
                ['shopList.page']:1
            }, () => {
                this.storeIncomeList()
            })
            break;
            case 1:
            this.setData({
                ['shopList.timeType']:1,
                ['shopList.page']: 1
            },() => {
                this.storeIncomeList()
            })
            break;
            case 2:
            this.setData({
                ['shopList.timeType']: 2,
                ['shopList.page']: 1
            }, () => {
                this.storeIncomeList()
            })
            break;
            case 3:
            this.setData({
                ['shopList.timeType']: 3,
                ['shopList.page']: 1
            }, () => {
                this.storeIncomeList()
            })
            break;
        }
        this.setData({
            loginNav:num
        })
    },
   
    //顶部信息
    storeDetail() {
        $.p(app.wxApp.url +'agentStore/storeDetail', {
            storeId: this.data.storeId
        }, app.onStrart, (res) => {
            this.setData({
                topContent:res.data
            })
            app.onShop();
        }, (res) => {
            util.showToast(res.data)
        })
    },
    //中部信息
    storeMoney() {
        $.p(app.wxApp.url + 'agentStore/storeMoney', {
            storeId: this.data.storeId,
        }, app.onStrart, (res) => {
            this.setData({
                centreContent:res.data
            })
            app.onShop();
        }, (res) => {
            util.showToast(res.data)
        })
    },

    //底部信息
    storeIncomeList() {
        const list = this.data.shopList
        $.p(app.wxApp.url + 'agentStore/storeIncomeList', {
            storeId: this.data.storeId,
            timeType: list.timeType,
            page: list.page,
            size: list.size
        }, app.onStrart, (res) => {
            let data = this.data.content
            if (res.data.page === 1) {
                data = res.data.list
            } else {
                res.data.list.map((item) => {
                    data.push({
                        ...item
                    })
                })
            }
            this.setData({
                content: data
            })
            app.onShop();
        }, (res) => {
            util.showToast(res.data)
        })
    },
   
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.setData({
            ['shopList.timeType']: 1,
            ['shopList.page']: 1,
            loginNav:1,
        }, () => {
            this.storeDetail()
            this.storeIncomeList()
            this.storeMoney()
        })
        wx.stopPullDownRefresh()
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.data.shopList.page++ ,
        this.storeIncomeList()
    },

   
})